package src.CodeTopSecondPractice;

public class _415 {
    public String addStrings(String num1, String num2) {
        StringBuilder sb = new StringBuilder();
        int cur1 = num1.length() - 1, cur2 = num2.length() - 1;
        int carry = 0;
        while (cur1 >= 0 || cur2 >= 0) {
            int n1 = cur1 >= 0 ? num1.charAt(cur1) - '0' : 0;
            int n2 = cur2 >= 0 ? num2.charAt(cur2) - '0' : 0;
            int temp = n1 + n2 + carry;
            carry = temp / 10;
            int real = temp % 10;
            sb.append(real);
            cur1--;
            cur2--;
        }
        if (carry != 0) {
            sb.append(carry);
        }
        return sb.reverse().toString();
    }
}
